#include <algorithm>
#include "Graph.h"
#include "Stripped_polyline.h"

namespace Graph_lib{

void Stripped_closed_polyline::draw_lines() const{
    //Closed_polyline::draw_lines();    
    int max_y=point(0).y;
    int min_y=point(0).y;
    int max_x=point(0).x;
    int min_x=point(0).x;
    
    for (int i=0;i<number_of_points();++i){
       if (point(i).y<min_y) min_y=point(i).y;  
       if (point(i).y>max_y) max_y=point(i).y;  
       if (point(i).x<min_x) min_x=point(i).x;  
       if (point(i).x>min_x) max_x=point(i).x;  
    }   
    
    for (int y=min_y;y<=max_y;y+=2){
        Point in(0,0);
        vector <int> pts;
        for(int i=0;i<number_of_points();++i)
            if (line_segment_intersect(Point(min_x,y),Point(max_x,y),point(i),point(i+1),in))
                pts.push_back(in.x);
        
        if (line_segment_intersect(Point(min_x,y),Point(max_x,y),point(0),point(number_of_points()-1),in))
            pts.push_back(in.x);
        sort(pts.begin(),pts.end());
        for (int i=0;i<pts.size()-1;++i)
            fl_line(pts[i],y,pts[i+1],y);
    }
}

}
